
package com.yanqu.road.server.cmd.activity.douluodalu;

import com.yanqu.road.entity.activity.douluodalu.log.DouLuoDaLuTryTrainRecordData;
import com.yanqu.road.logic.pb.DouLuoDaLuPb;
import com.yanqu.road.pb.activity.douluodalu.DouLuoDaLuProto;
import com.yanqu.road.server.cmd.CrossUnionCommand;
import com.yanqu.road.server.cmd.CrossUnionCommand;
import com.yanqu.road.server.command.Cmd;
import com.yanqu.road.server.logic.MessageHelper;
import com.yanqu.road.server.manager.douluodalu.CrossDouLouDaLuActivity;
import com.yanqu.road.server.manager.douluodalu.CrossDouLuoDaLuMgr;
import com.yanqu.road.utils.YanQuMessageUtils;
import com.yanqu.road.message.YanQuMessage;
import com.yanqu.road.server.protocol.Protocol;

import java.util.ArrayList;
import java.util.List;

@Cmd(code = Protocol.C_DOU_LUO_DA_LU_BAO_KU_DRAW_RECORD, desc = "试炼宝库日志")
public class CrossDouLuoDaLuTryTrainRecordCmd extends CrossUnionCommand {

    long userId;

    private List<DouLuoDaLuTryTrainRecordData> noticeList = new ArrayList<>();

    @Override
    public boolean parseData(YanQuMessage packet) throws Exception {
        return true;
    }

    @Override
    public void execute(YanQuMessage packet) throws Exception {
        DouLuoDaLuProto.DouLuoDaLuCommonCrossReqMsg reqMsg = DouLuoDaLuProto.DouLuoDaLuCommonCrossReqMsg.parseFrom(packet.getBytes());
        userId = packet.getPlayerId();
        CrossDouLouDaLuActivity activity = CrossDouLuoDaLuMgr.getActivityOrNull(reqMsg.getActivityId(), groupId);
        if(activity != null){
            noticeList = activity.getRecordDataList();
        }
    }

    @Override
    public void sendData() {

        DouLuoDaLuProto.DouLuoDaLuTryTrainRecordRespMsg.Builder builder = DouLuoDaLuProto.DouLuoDaLuTryTrainRecordRespMsg.newBuilder();
        builder.setRet(0);
        for (int i = 0; i < noticeList.size(); i++) {
            DouLuoDaLuTryTrainRecordData notice = noticeList.get(i);
            builder.addRecordList(DouLuoDaLuPb.parseTryTrainMsg(notice));
        }
        MessageHelper.sendPacket(serverId, userId, YanQuMessageUtils.buildMessage(Protocol.U_DOU_LUO_DA_LU_BAO_KU_DRAW_RECORD, builder));

    }
}
